//package com.ruoyi.web.controller.system;
//
//
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.io.UnsupportedEncodingException;
//import java.util.*;
//
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//
//
//
//import com.ruoyi.system.mapper.CwPropertyMapper;
//import com.ruoyi.system.service.ICwPropertyService;
//import org.apache.ibatis.annotations.Mapper;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//
//import org.springframework.web.bind.annotation.*;
//
//
//@Mapper
//@Controller
//@RequestMapping(value = "/returnPay")
//public class ReturnController {
//
//    @Autowired
//    private ICwPropertyService iCwPropertyService;
//
//
//
//    /**
//     * 支付宝回调的接口
//     *
//     * @param
//     * @return
//     * @throws IOException
//     */
////    @RequestMapping(value = "/aliReturnPay", method = RequestMethod.POST)
////    public void returnPay(HttpServletResponse response, AliReturnPayBean returnPay, HttpServletRequest req,Ggf ggf)
////            throws IOException {
////        response.setContentType("type=text/html;charset=UTF-8");
////        logger.info("****************************************支付宝的的回调函数被调用******************************");
////        if (!Alipay.checkSign(req)) {
////            logger.info("****************************************验签失败*******************************************");
////            response.getWriter().write("failture");
////            return;
////        }
////        if (returnPay == null) {
////            logger.info("支付宝的returnPay返回为空");
////            response.getWriter().write("success");
////            return;
////        }
////        logger.info("支付宝的returnPay" + returnPay.toString());
////        if (returnPay.getTrade_status().equals("TRADE_SUCCESS")) {
////            logger.info("支付宝的支付状态为TRADE_SUCCESS");
////           ggfService.updggfid(ggf);
////            System.out.println(ggf);
////        }
////        response.getWriter().write("success");
////    }
//
//
//
//    /**
//     * 支付宝支付后同步回调方法
//     * @param request
//     * @param response
//     */
//    @RequestMapping("/return")
//    public String returnCallback(HttpServletRequest request, HttpServletResponse response){
//
//        System.out.println("**************************同步回调方法执行*******************************************");
//        //获取支付宝GET过来反馈信息
//
////        Map<String,String> params = new HashMap<String,String>();
////        Map requestParams = request.getParameterMap();
////        try {
////            for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
////                String name = (String) iter.next();
////                String[] values = (String[]) requestParams.get(name);
////                String valueStr = "";
////                for (int i = 0; i < values.length; i++) {
////                    valueStr = (i == values.length - 1) ? valueStr + values[i]
////                            : valueStr + values[i] + ",";
////                }
////                //乱码解决，这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
////                valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
////                params.put(name, valueStr);
////            }
////            System.out.println("params---------->"+params);
////            //调用SDK验证签名
////            boolean signVerified = AlipaySignature.rsaCheckV2(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type);
////            if (signVerified){
//////                Ggf ggf=new Ggf();
////                //商户订单号
////                String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
////                //支付宝交易号
////                String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
////                //付款金额
////                String total_amount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"),"UTF-8");
////
////                //TODO 将支付宝返回的数据记录到数据库中
////                //1、根据订单号查询订单是否存在，
////                //2、根据支付宝返回的trade_status状态进行下一步要操作，成功：更新订单状态，
//////                response.getWriter().write("success");
////                System.out.println("okokokok");
////                return "success";
////
////            }else {
////                return "fail";
//////                 response.getWriter().write("fail");
////            }
////
////        }catch (Exception e){
////            e.printStackTrace();
////            throw new RuntimeException("回调异常");
////        }
//
//
//        HttpSession session = request.getSession(true);
//        System.out.println(session.getAttribute("pid"));
//        Integer pid= (Integer) session.getAttribute("pid");
//
//
//
//
//
//            iCwPropertyService.updstatus(pid);
//
//
//
//
//
//
////        System.out.println(ggf+"dfghjkl");
//        return "success";
//    }
//
//    /**
//     * 支付订单后异步回调方法
//     * @param
//     * @param
//     * @return
//     */
////    @PostMapping("/notify")
////    @ResponseBody
////    public String notifyUrl(HttpServletRequest request,HttpServletResponse response){
////        //获取支付宝POST过来反馈信息
////        Map<String,String> params = new HashMap<String,String>();
////        Map<String,String[]> requestParams = request.getParameterMap();
////        try {
////            for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext();) {
////                String name = (String) iter.next();
////                String[] values = (String[]) requestParams.get(name);
////                String valueStr = "";
////                for (int i = 0; i < values.length; i++) {
////                    valueStr = (i == values.length - 1) ? valueStr + values[i]
////                            : valueStr + values[i] + ",";
////                }
////                //乱码解决，这段代码在出现乱码时使用
////                valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
////                params.put(name, valueStr);
////            }
////            System.out.println("支付宝支付返回参数params-------->"+params);
////            boolean signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type); //调用SDK验证签名
////            System.out.println("signVerified----->"+signVerified);
////            PrintWriter out = null;
////            if (signVerified){
////                Ggf ggf=new Ggf();
////                //商户订单号  orderNo
////                String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8");
////                //支付宝交易号
////                String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8");
////                //买家支付宝交易账号
////                String buyer_id = new String(request.getParameter("buyer_id").getBytes("ISO-8859-1"),"UTF-8");
////                //交易总金额
////                String total_amount = new String(request.getParameter("total_amount").getBytes("ISO-8859-1"),"UTF-8");
////                //实收金额
////                String receipt_amount = new String(request.getParameter("receipt_amount").getBytes("ISO-8859-1"),"UTF-8");
////                //付款金额
////                String buyer_pay_amount = new String(request.getParameter("buyer_pay_amount").getBytes("ISO-8859-1"),"UTF-8");
////                //交易时间
////                String gmt_create = new String(request.getParameter("gmt_create").getBytes("ISO-8859-1"),"UTF-8");
////                //交易付款时间
////                String gmt_payment = new String(request.getParameter("gmt_payment").getBytes("ISO-8859-1"),"UTF-8");
////                //获取appid
////                String app_id = new String(request.getParameter("app_id").getBytes("ISO-8859-1"),"UTF-8");
////                //交易状态
////                String trade_status = new String(request.getParameter("trade_status").getBytes("ISO-8859-1"),"UTF-8");
////
////
////                //根据订单查询该订单是否存在
////                if (trade_no == null){
////                    throw new AlipayApiException("out_trade_no错误");
////                }else{
////                    ggfService.updggfid(ggf);
////                    System.out.println("lllllllllllllllllllllllll"+ggf);
////                }
//////                //判断支付金额是否正确
//////                if (!total_amount.equals(memberOrder.getTotalFee().toString())){
//////                    throw new AlipayApiException("error total_amount");
//////                }
////                //判断appid是否一致
////                if (!app_id.equals(AlipayConfig.app_id)){
////                    throw new AlipayApiException("app_id不一致");
////                }
////                System.out.println("trade_status------------>"+trade_status);
////                if(trade_status.equals("TRADE_FINISHED")){
////                    //判断该笔订单是否在商户网站中已经做过处理
////                    //如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
////                    //如果有做过处理，不执行商户的业务程序
////
////                    //注意：
////                    //退款日期超过可退款期限后（如三个月可退款），支付宝系统发送该交易状态通知
////                }else if (trade_status.equals("TRADE_SUCCESS")){//向支付宝订单记录表中添加数据
////                    //判断该笔订单是否在商户网站中已经做过处理
////                    //如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
////                    //如果有做过处理，不执行商户的业务程序
////                    //注意：
////                    //付款完成后，支付宝系统发送该交易状态通知
////                }
//////                response.getOutputStream().print("success");
////                return "success";
////                //
////            }else {//验签失败
////                // response.getOutputStream().print("failure");
////                return "failure";
////            }
////        }catch (AlipayApiException e) {
////            System.out.println(e.getErrMsg());
////            throw new RuntimeException("调用支付宝接口发生异常");
////        } catch (UnsupportedEncodingException e) {
////            System.out.println(e.getMessage());
////            throw new RuntimeException("URLDecoderf发生异常");
////        } /*catch (IOException e) {
////            System.out.println(e.getMessage());
////            throw new RuntimeException("IO发生异常");
////        }*/
////    }
//
//
//
//
//}
